<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />

    

    

    <title>springcloud-admin监控模块搭建 | 郑礼德技术栈</title>
    <meta name="author" content="郑礼德" />
    <meta name="keywords" content="" />
    <meta name="description" content="springboot admin 可以对springboot 应用的各项指标进行监控，可以作为微服务架构中的监控中心进行使用创建erp-admin 模块本次案例是在做一个erp系统中添加的，作为这个系统的监控中心在pom中添加依赖&amp;lt;dependency&amp;gt;    &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;    &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;..." />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />

    
    <link rel="alternate" href="/homepage/atom.xml" title="郑礼德技术栈" type="application/atom+xml">
    
    
    <link rel="icon" href="/homepage/images/favicon.ico">
    

    <style type="text/css">
    @font-face {
        font-family: 'icomoon';
        src: url("/homepage/fonts/icomoon.eot?q628ml");
        src: url("/homepage/fonts/icomoon.eot?q628ml#iefix") format('embedded-opentype'),
             url("/homepage/fonts/icomoon.ttf?q628ml") format('truetype'),
             url("/homepage/fonts/icomoon.woff?q628ml") format('woff'),
             url("/homepage/fonts/icomoon.svg?q628ml#icomoon") format('svg');
        font-weight: normal;
        font-style: normal;
    }
    </style>
    
<link rel="stylesheet" href="/homepage/css/style.css">


    <!--[if lt IE 9]>
    <style type="text/css">
    .nav-inner {top:0;}
    .author-meta {position:static;top:0;}
    .search-form {height:36px;}
    </style>
    <script type="text/javascript" src="https://unpkg.com/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <![endif]-->
<meta name="generator" content="Hexo 4.2.0"></head>
<body>

    <main class="app">
        <header id="header" class="header clearfix">
    <div id="nav" class="nav">
    <div class="nav-mobile">
        <button id="open-panel" class="open-panel nav-mobile-item"><i class="icon-documents"></i></button>
        <h1 class="nav-mobile-title nav-mobile-item">郑礼德技术栈</h1>
        <button id="open-menus" class="open-panel nav-mobile-item"><i class="icon-library"></i></button>
    </div>

    <nav id="nav-inner" class="nav-inner">
        
            <a class="nav-item" href="/homepage/">
                <span class="nav-text">首页</span>
            </a>
        
            <a class="nav-item" href="/homepage/categories/front-end">
                <span class="nav-text">前端</span>
            </a>
        
            <a class="nav-item" href="/homepage/categories/back-end">
                <span class="nav-text">后端</span>
            </a>
        
            <a class="nav-item" href="/homepage/categories/linux">
                <span class="nav-text">linux部署</span>
            </a>
        
            <a class="nav-item" href="/homepage/tags">
                <span class="nav-text">标签</span>
            </a>
        
            <a class="nav-item" href="/homepage/archives">
                <span class="nav-text">归档</span>
            </a>
        
            <a class="nav-item" href="/homepage/about">
                <span class="nav-text">关于</span>
            </a>
        
    </nav>
</div>

    <aside id="aside" class="aside">
    <div id="aside-mask" class="aside-mask"></div>
    <div id="aside-inner" class="aside-inner">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit"><i class="icon-search-stroke"></i></button><input type="hidden" name="sitesearch" value="http://zhenglide.gitee.io/homepage"></form>

        
        
        
        

        
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#创建erp-admin-模块"><span class="toc-number">1.</span> <span class="toc-text">创建erp-admin 模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#在pom中添加依赖"><span class="toc-number">1.1.</span> <span class="toc-text">在pom中添加依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#在yml-进行配置"><span class="toc-number">1.2.</span> <span class="toc-text">在yml 进行配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#启动类加上-EnableAdminServer-注解"><span class="toc-number">1.3.</span> <span class="toc-text">启动类加上@EnableAdminServer 注解</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建admin-client-客户端"><span class="toc-number">2.</span> <span class="toc-text">创建admin-client 客户端</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#在pom中添加相关依赖"><span class="toc-number">2.1.</span> <span class="toc-text">在pom中添加相关依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#在application-yml-进行配置"><span class="toc-number">2.2.</span> <span class="toc-text">在application.yml 进行配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#结合注册中心使用"><span class="toc-number">3.</span> <span class="toc-text">结合注册中心使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#修改erp-admin"><span class="toc-number">3.1.</span> <span class="toc-text">修改erp-admin</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#在pom中添加相关依赖-1"><span class="toc-number">3.1.1.</span> <span class="toc-text">在pom中添加相关依赖</span></a></li></ol></li></ol></li></ol>
        
    </div>
</aside>

</header>

        <div id="content" class="content">
            <div id="wrapper" class="wrapper" style="max-width: 800px">
                <article class="article" itemscope itemprop="blogPost">
    
    <header class="article-header">
        
        <h1 itemprop="name">
            springcloud-admin监控模块搭建
        </h1>
        
        <div class="article-meta clearfix">
            <a class="article-date" href="http://zhenglide.gitee.io/homepage/2020/04/13/springcloud-admin%E7%9B%91%E6%8E%A7%E6%A8%A1%E5%9D%97%E6%90%AD%E5%BB%BA/index.html">
    
    <i class="icon-calendar"></i>
    
    <time datetime="2020-04-13T07:26:54.000Z" itemprop="datePublished">2020-04-13</time>
</a>

            
<div class="article-tag-list">
    <i class="icon-tag"></i>
    <a class="article-tag-link" href="/homepage/tags/springboot/" rel="tag">springboot</a>, <a class="article-tag-link" href="/homepage/tags/springcloud/" rel="tag">springcloud</a>
</div>


        </div>
    </header>
    
    <section class="article-body markdown-body">
        
        <p>springboot admin 可以对springboot 应用的各项指标进行监控，可以作为微服务架构中的监控中心进行使用</p>
<a id="more"></a>

<h2 id="创建erp-admin-模块"><a href="#创建erp-admin-模块" class="headerlink" title="创建erp-admin 模块"></a>创建erp-admin 模块</h2><p>本次案例是在做一个erp系统中添加的，作为这个系统的监控中心</p>
<h3 id="在pom中添加依赖"><a href="#在pom中添加依赖" class="headerlink" title="在pom中添加依赖"></a>在pom中添加依赖</h3><pre><code class="xml">&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-server --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;de.codecentric&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-admin-starter-server&lt;/artifactId&gt;
    &lt;version&gt;2.1.0&lt;/version&gt;
&lt;/dependency&gt;

</code></pre>
<h3 id="在yml-进行配置"><a href="#在yml-进行配置" class="headerlink" title="在yml 进行配置"></a>在yml 进行配置</h3><pre><code class="yaml">spring:
  application:
    name: admin-server
server:
  port: 9301
</code></pre>
<h3 id="启动类加上-EnableAdminServer-注解"><a href="#启动类加上-EnableAdminServer-注解" class="headerlink" title="启动类加上@EnableAdminServer 注解"></a>启动类加上@EnableAdminServer 注解</h3><pre><code class="java">@EnableAdminServer
@SpringBootApplication
public class ErpAdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(ErpAdminApplication.class, args);
    }

}</code></pre>
<h2 id="创建admin-client-客户端"><a href="#创建admin-client-客户端" class="headerlink" title="创建admin-client 客户端"></a>创建admin-client 客户端</h2><p>这里以erp-security 作为演示例子</p>
<h3 id="在pom中添加相关依赖"><a href="#在pom中添加相关依赖" class="headerlink" title="在pom中添加相关依赖"></a>在pom中添加相关依赖</h3><pre><code class="xml">&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;de.codecentric&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-admin-starter-client&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>
<h3 id="在application-yml-进行配置"><a href="#在application-yml-进行配置" class="headerlink" title="在application.yml 进行配置"></a>在application.yml 进行配置</h3><pre><code class="yaml">spring:
  application:
    name: admin-client
  boot:
    admin:
      client:
        url: http://localhost:9301 #配置admin-server地址
server:
  port: 9305
management:
  endpoints:
    web:
      exposure:
        include: &#39;*&#39;
  endpoint:
    health:
      show-details: always
logging:
  file: admin-client.log #添加开启admin的日志监控
</code></pre>
<p>启动两个服务查看监控信息</p>
<img src="/homepage/2020/04/13/springcloud-admin%E7%9B%91%E6%8E%A7%E6%A8%A1%E5%9D%97%E6%90%AD%E5%BB%BA/%E6%9F%A5%E7%9C%8B%E7%9B%91%E6%8E%A7%E4%BF%A1%E6%81%AF.png" class="">

<h2 id="结合注册中心使用"><a href="#结合注册中心使用" class="headerlink" title="结合注册中心使用"></a>结合注册中心使用</h2><p>admin-server 会从注册中心中获取注册列表，监控信息</p>
<h3 id="修改erp-admin"><a href="#修改erp-admin" class="headerlink" title="修改erp-admin"></a>修改erp-admin</h3><h4 id="在pom中添加相关依赖-1"><a href="#在pom中添加相关依赖-1" class="headerlink" title="在pom中添加相关依赖"></a>在pom中添加相关依赖</h4>
        
    </section>
</article>



<a id="pagenext" href="/homepage/2020/04/05/%E6%B5%85%E8%B0%88%E4%BD%BF%E7%94%A8%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E5%87%8F%E5%B0%91if-else/" class="article-next" title="浅谈使用设计模式减少if-else"><i class="icon-arrow-right"></i></a>


<a id="pageprev" href="/homepage/2020/04/13/%E4%BD%BF%E7%94%A8docker%E5%AE%89%E8%A3%85oracle/" class="article-prev" title="使用docker安装oracle"><i class="icon-arrow-left"></i></a>




            </div>
        </div>
        <footer class="footer">
    Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>, Theme by <a href="https://github.com/sanonz/hexo-theme-concise" target="_blank">Concise</a>

    
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b13bb4c2ef8300062aab9732bd22eae0";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>
    
</footer>

    </main>

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        var nodes = {
            nav: $('#nav'),
            aside: $('#aside'),
            asideInner: $('#aside-inner'),
            navInner: $('#nav-inner')
        };

        var doing = false;
        nodes.asideInner.on('webkitAnimationEnd mozAnimationEnd oAnimationEnd oanimationend animationend', function() {
            if (nodes.aside.hasClass('mobile-open')) {
                nodes.aside.removeClass('mobile-open');
            } else {
                nodes.aside.removeClass('mobile-close panel-show');
            }
            doing = false;
        });
        $('#open-panel, #aside-mask').on('click', function() {
            if (doing) {
                return;
            }

            if (nodes.aside.hasClass('panel-show')) {
                nodes.aside.addClass('mobile-close');
            } else {
                nodes.aside.addClass('mobile-open panel-show');
            }
        });
        $('#open-menus').on('click', function() {
            nodes.navInner.slideToggle();
        });

        if (window.innerWidth <= 960) {
            setTimeout(function() {
                nodes.navInner.slideUp();
            }, 3000);
        }
    });
    </script>
    
        
<script src="/homepage/js/scrollspy.min.js"></script>

        <script type="text/javascript">
        $(document.body).scrollspy({target: '#aside-inner'});

        $(window).on('resize', function() {
            var hw = $('#header').width();
            var ww = $('#wrapper').width();
            var space = ($(this).width() - hw - ww) / 2 / 2;

            var pageprev = $('#pageprev');
            var pagenext = $('#pagenext');
            var avg = (pageprev.width() + pagenext.width()) / 2

            if(space > avg) {
                var len = space - avg / 2;
                var styles = {position: 'fixed', top: '50%', marginTop: - (pageprev.width() + pagenext.width()) / 4}
                pageprev.css($.extend({left: hw + len}, styles));
                pagenext.css($.extend({right: len}, styles));
            } else {
                pageprev.removeAttr('style');
                pagenext.removeAttr('style');
            }
        }).trigger('resize');
        </script>
    

</body>
</html>
